package hiep.homework4;

import hiep.homework4.DatabaseHelper;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME = "dbSinhVien.sqlite";
	private static final int DATABASE_VERSION = 1;
	public static final String TABLE_SinhVien = "tblSinhVien";
	public static final String ID_SV = "ID";
	public static final String Name_SV = "Name";
	public static final String Age_SV = "Age";
	public static final String Country_SV = "Country";
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_SinhVien + "(" + ID_SV
			+ " integer primary key autoincrement not null, " + Name_SV
			+ " VARCHAR(128), " + Age_SV + " INTEGER, " + Country_SV
			+ " VARCHAR(64));";

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.e(DatabaseHelper.class.getName(), "Cập nhật CSDL từ phiên bản "
				+ oldVersion + " đến " + newVersion
				+ ", vui lòng kiểm tra cẩn thẩn để tránh tổn thất dữ liệu cũ");

		db.execSQL("CREATE TABLE \"tblRSS\" (\"ID_RSS\" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , \"Name_RSS\" TEXT, \"Link_RSS\" TEXT)");
	}
}
